package main

import (
	"github.com/mmcdole/gofeed"
	"log"
	"time"
)

var methods = map[string]func(feed *gofeed.Feed, json []Data) []Data{
	"mikan": mikan,
}

func mikan(feed *gofeed.Feed, json []Data) []Data {
	var newList []Data
A:
	for _, item := range feed.Items {
		for _, data := range json {
			if item.Title == data.Title {
				continue A
			}
		}
		data := Data{
			Title:   item.Title,
			Torrent: getLastSegment(item.Link),
			Date:    time.Now().Format("2006-01-02 15:04:05"),
		}
		newList = append(newList, data)
		send2Gotify("有新番更新了!", "标题："+data.Title+"\n种子："+data.Torrent+"\n日期: "+data.Date, 10, nil)
	}
	if len(newList) != 0 {
		log.Printf("更新了%v部番剧", len(newList))
	}
	newList = append(newList, json...)
	return newList
}

type Data struct {
	Title   string `json:"title"`
	Torrent string `json:"torrent"`
	Date    string `json:"date"`
}
